﻿/*Copyright by Zak - http://www.xnamag.de/forum/viewtopic.php?t=1062 */
namespace MECopter.Joystick
{
    //----------------------------------------------------------------- 
    // JoystickCapabilities Struktur 
    //----------------------------------------------------------------- 
    public struct JoystickCapabilities
    {
        /// <summary> 
        /// Anzahl der Achsen. 
        /// </summary>    
        public uint AxisCount
        {
            get { return (wNumAxis); }
        }
        internal uint wNumAxis;
        /// <summary> 
        /// Anzahl der Tasten. 
        /// </summary>  
        public uint ButtonCount
        {
            get { return (wNumButtons); }
        }
        internal uint wNumButtons;
        /// <summary> 
        /// Min. Wert der X-Achse. 
        /// </summary>  
        public uint MinAxisX
        {
            get { return (wXmin); }
        }
        internal uint wXmin;
        /// <summary> 
        /// Max. Wert der X-Achse. 
        /// </summary>    
        public uint MaxAxisX
        {
            get { return (wXmax); }
        }
        internal uint wXmax;
        /// <summary> 
        /// Min. Wert der Y-Achse. 
        /// </summary>    
        public uint MinAxisY
        {
            get { return (wYmin); }
        }
        internal uint wYmin;
        /// <summary> 
        /// Max. Wert der Y-Achse. 
        /// </summary>    
        public uint MaxAxisY
        {
            get { return (wYmax); }
        }
        internal uint wYmax;
        /// <summary> 
        /// Min. Wert der Z-Achse. 
        /// </summary>    
        public uint MinAxisZ
        {
            get { return (wZmin); }
        }
        internal uint wZmin;
        /// <summary> 
        /// Max. Wert der Z-Achse. 
        /// </summary>  
        public uint MaxAxisZ
        {
            get { return (wZmax); }
        }
        internal uint wZmax;
        /// <summary> 
        /// Min. Wert der R-Achse. 
        /// </summary>    
        public uint MinAxisR
        {
            get { return (wRmin); }
        }
        internal uint wRmin;
        /// <summary> 
        /// Max. Wert der R-Achse. 
        /// </summary>    
        public uint MaxAxisR
        {
            get { return (wRmax); }
        }
        internal uint wRmax;
        /// <summary> 
        /// Min. Wert der U-Achse. 
        /// </summary>    
        public uint MinAxisU
        {
            get { return (wUmin); }
        }
        internal uint wUmin;
        /// <summary> 
        /// Max. Wert der U-Achse. 
        /// </summary>    
        public uint MaxAxisU
        {
            get { return (wUmax); }
        }
        internal uint wUmax;
        /// <summary> 
        /// Min. Wert der V-Achse. 
        /// </summary>    
        public uint MinAxisV
        {
            get { return (wVmin); }
        }
        internal uint wVmin;
        /// <summary> 
        /// Max. Wert der V-Achse. 
        /// </summary>    
        public uint MaxAxisV
        {
            get { return (wVmax); }
        }
        internal uint wVmax;
    }

    //----------------------------------------------------------------- 
    // JoystickState Struktur 
    //----------------------------------------------------------------- 
    public struct JoystickState
    {
        /// <summary> 
        /// Ist der Joystick angeschlossen. 
        /// </summary> 
        public bool isConnected
        {
            get { return (bConnected); }
        }
        internal bool bConnected;
        /// <summary> 
        /// Position der X-Achse 
        /// </summary> 
        public uint PositionAxisX
        {
            get { return (dwXpos); }
        }
        internal uint dwXpos;
        /// <summary> 
        /// Position der Y-Achse 
        /// </summary> 
        public uint PositionAxisY
        {
            get { return (dwYpos); }
        }
        internal uint dwYpos;
        /// <summary> 
        /// Position der Z-Achse 
        /// </summary> 
        public uint PositionAxisZ
        {
            get { return (dwZpos); }
        }
        internal uint dwZpos;
        /// <summary> 
        /// Position der R-Achse 
        /// </summary> 
        public uint PositionAxisR
        {
            get { return (dwRpos); }
        }
        internal uint dwRpos;
        /// <summary> 
        /// Position der U-Achse 
        /// </summary> 
        public uint PositionAxisU
        {
            get { return (dwUpos); }
        }
        internal uint dwUpos;
        /// <summary> 
        /// Position der V-Achse 
        /// </summary> 
        public uint PositionAxisV
        {
            get { return (dwVpos); }
        }
        internal uint dwVpos;
        /// <summary> 
        /// Taste 
        /// </summary> 
        public uint Button
        {
            get { return (dwButton); }
        }
        internal uint dwButton;
        /// <summary> 
        /// Anzahl der gedrückten Tasten 
        /// </summary> 
        public uint ButtonPressedCount
        {
            get { return (dwButtonNumber); }
        }
        internal uint dwButtonNumber;
        /// <summary> 
        /// POV Richtung (DPad) 
        /// </summary> 
        public uint POV
        {
            get { return (dwPOV); }
        }
        internal uint dwPOV;

        //----------------------------------------------------------------- 
        // Hilfsfunktionen für die Tastenabfrage 
        //----------------------------------------------------------------- 
        /// <summary> 
        /// Gibt an ob eine bestimmte Taste gedrückt ist. 
        /// </summary> 
        /// <param name="joystickButton">Joystick Taste</param> 
        /// <returns></returns> 
        public bool isButtonDown(JoystickButtons joystickButton)
        {
            return (((uint)(joystickButton) & dwButton) == (uint)joystickButton);
        }

        /// <summary> 
        /// Gibt an ob eine bestimmte Taste nicht gedrückt ist. 
        /// </summary> 
        /// <param name="joystickButton">Joystick Taste</param> 
        /// <returns></returns> 
        public bool isButtonUp(JoystickButtons joystickButton)
        {
            return (((uint)(joystickButton) & dwButton) == 0);
        }

        //----------------------------------------------------------------- 
        // Hilfsfunktionen für die Tastenabfrage 
        //----------------------------------------------------------------- 
        /// <summary> 
        /// Gibt an ob eine bestimmte POV (DPad) Richtung gedrückt ist. 
        /// </summary> 
        /// <param name="joystickPOV">POV Richtung</param> 
        /// <returns></returns> 
        public bool isPovDown(JoystickPOV joystickPOV)
        {
            return (((uint)(joystickPOV) == dwPOV));
        }

        /// <summary> 
        /// Gibt an ob eine bestimmte POV (DPad) Richtung nicht gedrückt ist. 
        /// </summary> 
        /// <param name="joystickPOV"></param> 
        /// <returns></returns> 
        public bool isPovUp(JoystickPOV joystickPOV)
        {
            return (((uint)(joystickPOV) != dwPOV));
        }

        /// <summary> 
        /// Gibt an ob POV (DPad) in Mittelstellung ist. 
        /// </summary> 
        /// <returns></returns> 
        public bool isPovCentered()
        {
            return (((uint)0xFFFF == dwPOV));

        }
    }
}
